{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "ename": "ZeroDivisionError",
     "evalue": "division by zero",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mZeroDivisionError\u001B[0m                         Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[2], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m result \u001B[38;5;241m=\u001B[39m \u001B[38;5;241;43m10\u001B[39;49m\u001B[43m \u001B[49m\u001B[38;5;241;43m/\u001B[39;49m\u001B[43m \u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\n\u001B[0;32m      2\u001B[0m \u001B[38;5;28mprint\u001B[39m(result)\n",
      "\u001B[1;31mZeroDivisionError\u001B[0m: division by zero"
     ]
    }
   ],
   "source": [
    "result = 10 / 0\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-15T18:58:14.478519100Z",
     "start_time": "2023-12-15T18:58:14.112838400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-12-15T18:49:14.026999100Z",
     "start_time": "2023-12-15T18:49:14.009455800Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "division by zero\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # 代码块，可能会抛出异常\n",
    "    result = 10 / 0\n",
    "except ZeroDivisionError as e:\n",
    "    # 处理ZeroDivisionError异常\n",
    "    print(f\"Error: {e}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: invalid literal for int() with base 10: 'abc'\n",
      "result变量是字符串\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # 代码块，可能会抛出异常\n",
    "    result = int(\"abc\")\n",
    "except (ValueError, TypeError) as e:\n",
    "    # 处理ValueError和TypeError异常\n",
    "    print(f\"Error: {e}\")\n",
    "    print(\"result变量是字符串\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-15T19:14:17.002045Z",
     "start_time": "2023-12-15T19:14:16.987448400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: division by zero\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # 代码块，可能会抛出异常\n",
    "    result = 10 / 0\n",
    "except Exception as e:\n",
    "    # 处理所有类型的异常\n",
    "    print(f\"Error: {e}\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-15T19:16:30.478559200Z",
     "start_time": "2023-12-15T19:16:30.465905700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: division by zero\n",
      "Finally block executed\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # 代码块，可能会抛出异常\n",
    "    result = 10 / 0\n",
    "except ZeroDivisionError as e:\n",
    "    # 处理ZeroDivisionError异常\n",
    "    print(f\"Error: {e}\")\n",
    "finally:\n",
    "    # 无论是否发生异常，都会执行的代码\n",
    "    print(\"Finally block executed\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-15T19:18:27.288118100Z",
     "start_time": "2023-12-15T19:18:27.274767500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: Custom error message\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # 代码块，可能会抛出异常\n",
    "    raise ValueError(\"Custom error message\")\n",
    "except ValueError as e:\n",
    "    # 处理自定义异常\n",
    "    print(f\"Error: {e}\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-15T19:19:49.056764Z",
     "start_time": "2023-12-15T19:19:49.042742200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
